/*
 * @FilePath: \network\src\store\index.js
* @Description: In User Settings Edit
*/
//第一步，引入vue和vuex
import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

//第二步，创建一个store
let store = new Vuex.Store({
  state: localStorage.getItem('state') ? JSON.parse(localStorage.getItem('state')) : {
    // 存储token
    token: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : '', //名称与接口一致
    refreshToken: localStorage.getItem('refreshToken') ? localStorage.getItem('refreshToken') : '', //名称与接口一致
    user_Id: localStorage.getItem('user_Id') ? localStorage.getItem('user_Id') : '', //登录人ID
    userInfo: localStorage.getItem('userInfo') ? localStorage.getItem('userInfo') : '', //登录人信息
    departmentTreeData:[],
    breadTagList:localStorage.getItem('breadTagList') ? localStorage.getItem('breadTagList') : [], //面包屑按钮菜单
    SystemTitle:''			//读取配置信息成功后存储名称
  },
  getters: {

  },
  mutations: {

    // 修改token，并将token存入localStorage
    changeLogin(state, user) {
      state.token = user[0].Authorization;
      localStorage.setItem('Authorization', user[0].Authorization);
      state.user_Id = user[1].user_Id;
      localStorage.setItem('user_Id', user[1].user_Id);
      // state.refreshToken = user[2].refreshToken;
      // localStorage.setItem('user_Id', user[2].refreshToken);

      // state.userInfo = user[3].userInfo;
      // localStorage.setItem('userInfo', user[3].userInfo);
    },
    remakeToken(state,data) {
      state.token = data.data.token;
      localStorage.setItem('Authorization', data.data.token);
      // state.refreshToken = data.data.refreshToken;
      // localStorage.setItem('refreshToken', data.data.refreshToken);

    },
    //处理部门数组中为空的那层details
    delDpartment(state,tree){
      state.departmentTreeData = tree;
    },
    //存面包屑菜单列表
    storageBread(state,list){
      state.breadTagList = list
      localStorage.setItem('breadTagList', list);
    },
    //清空缓存
    clearOut(state){
      state.breadTagList = []
    },
  }
})

//第三步，将store暴露
export default store
